{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-14T07:36:42.165041Z",
     "start_time": "2019-11-14T07:36:32.866936Z"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "\n",
    "# 指定工作目录路径\n",
    "os.chdir('D:\\迁移率')\n",
    "data = pd.read_csv('order_repay.csv',low_memory=False)\n",
    "data1 = data.drop(columns='记录数')\n",
    "data=data1.copy()\n",
    "name = list(data)\n",
    "# 把列名转为大写\n",
    "for n in name:\n",
    "#     print(n.upper())\n",
    "    data.rename(columns={n:n.upper()},inplace=True)\n",
    "data\n",
    "\n",
    "# 转换时间\n",
    "data['REPAY_TIME5'] = pd.to_datetime(data.REPAY_TIME5, format='%Y-%m-%d')\n",
    "data['REPAY_TIME6'] = pd.to_datetime(data.REPAY_TIME6, format='%Y-%m-%d')\n",
    "data['REPAY_TIME7'] = pd.to_datetime(data.REPAY_TIME7, format='%Y-%m-%d')\n",
    "data['REPAY_TIME8'] = pd.to_datetime(data.REPAY_TIME8, format='%Y-%m-%d')\n",
    "data['REPAY_TIME9'] = pd.to_datetime(data.REPAY_TIME9, format='%Y-%m-%d')\n",
    "data['REPAY_TIME10'] = pd.to_datetime(data.REPAY_TIME10, format='%Y-%m-%d')\n",
    "data['REPAY_TIME11'] = pd.to_datetime(data.REPAY_TIME11, format='%Y-%m-%d')\n",
    "data['COMPLETE_TIME'] = pd.to_datetime(data.COMPLETE_TIME, format='%Y-%m-%d').dt.month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-14T07:57:26.543187Z",
     "start_time": "2019-11-14T07:36:50.028093Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "迁移率数据写入完成！文件位置:D:\\迁移率\n"
     ]
    }
   ],
   "source": [
    "\n",
    "grant = ['ZHONGAN', 'ZHAOLIAN', 'MASHANGXIAOJIN', 'WEIXIN', 'ZIZHUSHOUXIN', 'BESTPAY', 'GUOFU',\n",
    "         'DUMIAO', 'FENQICHAOREN', 'ZIYING', 'TIANCHENGRONGZU', 'YUANDONGRONGZU', 'HUABEIPLEDGE']\n",
    "user = [1, 2, 3, 4, 5, 10, 12]\n",
    "area = [\"广东省\", \"江苏省\", \"重庆市\", \"四川省\", \"新疆维吾尔自治区\", \"浙江省\", \"内蒙古自治区\", \"湖北省\", \"辽宁省\",\"陕西省\",\"海南省\",\"山西省\",\"福建省\",\"甘肃省\",\"天津市\",\"宁夏回族自治区\"]\n",
    "\n",
    "\n",
    "# 计算逾期期数\n",
    "# x:series y:账期数\n",
    "def overdue_num(x, y):\n",
    "    o_num = 0\n",
    "    for i in range(5, y + 1):\n",
    "        o_num = o_num + int(x['STATUS' + str(i)] == 'OPEN') + int(\n",
    "            x['REPAY_TIME' + str(i)] >= pd.to_datetime('2019-' + str(y) + '-11'))\n",
    "    return o_num\n",
    "\n",
    "\n",
    "for i in grant:\n",
    "    for j in user:\n",
    "        for k in area:\n",
    "            all = data.loc[(data['CREDIT_BY'] == i) & (data['USER_TYPE'] == j) & (data['ACCEPT_AREA_NAME'] == k)].copy()\n",
    "            if all.shape[0] == 0:\n",
    "                pass\n",
    "            else:\n",
    "                #                 print(all.shape)\n",
    "\n",
    "                # 按完成时间分类\n",
    "                m4 = all[all['COMPLETE_TIME'] == 4]\n",
    "                m5 = all[all['COMPLETE_TIME'] == 5]\n",
    "                m6 = all[all['COMPLETE_TIME'] == 6]\n",
    "                m7 = all[all['COMPLETE_TIME'] == 7]\n",
    "                m8 = all[all['COMPLETE_TIME'] == 8]\n",
    "                m9 = all[all['COMPLETE_TIME'] == 9]\n",
    "                m10 = all[all['COMPLETE_TIME'] == 10]\n",
    "                m11 = all[all['COMPLETE_TIME'] == 11]\n",
    "                # 4月\n",
    "                # 按mob分类\n",
    "                # 4月完成\n",
    "                list_all_c_4 = list(m4['ACCOUNT_ID'])\n",
    "                # 5月\n",
    "                # 按mob分类\n",
    "                # 4月完成\n",
    "                list_m4_t_5 = list(m4[m4['STATUS5'] == 'TERMINATE']['ACCOUNT_ID']) + list(\n",
    "                    m4[m4['STATUS5'] == 'CLOSE']['ACCOUNT_ID'])\n",
    "                list_m4_m1_5 = list(m4[m4['STATUS5'] == 'OPEN']['ACCOUNT_ID']) + list(\n",
    "                    m4[m4['REPAY_TIME5'] >= '2019-5-11']['ACCOUNT_ID'])\n",
    "                list_m4_c_5 = list(set(m4['ACCOUNT_ID']) ^ set(list_m4_t_5 + list_m4_m1_5))\n",
    "\n",
    "                # 总的\n",
    "                list_all_t_5 = list_m4_t_5\n",
    "                list_all_m1_5 = list_m4_m1_5\n",
    "\n",
    "                list_all_c_5 = list_m4_c_5 + list(m5['ACCOUNT_ID'])\n",
    "\n",
    "                # 6月\n",
    "                # 取4月和五月完成的数据\n",
    "                m4_5 = all[all['COMPLETE_TIME'].isin(list(range(4, 6)))].copy()\n",
    "                if m4_5.shape[0] > 0:\n",
    "                    # 判断逾期几期并记录到dataframe\n",
    "                    m4_5['overdue_num'] = m4_5.apply(lambda x: overdue_num(x=x, y=6), axis=1)\n",
    "                else:\n",
    "                    m4_5['overdue_num'] = 0\n",
    "                list_all_m1_6 = list(m4_5[m4_5['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_6 = list(m4_5[m4_5['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_c_6 = list(\n",
    "                    m4_5.loc[(m4_5['STATUS6'] == 'CLEAR') & (m4_5['REPAY_TIME6'] < '2019-6-11')]['ACCOUNT_ID']) + list(\n",
    "                    m6['ACCOUNT_ID'])\n",
    "\n",
    "                # 7月\n",
    "                # 取4-6月完成的数据\n",
    "                m4_6 = all[all['COMPLETE_TIME'].isin(list(range(4, 7)))].copy()\n",
    "                if m4_6.shape[0] > 0:\n",
    "                    # 判断逾期几期并记录到dataframe\n",
    "                    m4_6['overdue_num'] = m4_6.apply(lambda x: overdue_num(x=x, y=7), axis=1)\n",
    "                else:\n",
    "                    m4_6['overdue_num'] = 0\n",
    "                list_all_m1_7 = list(m4_6[m4_6['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_7 = list(m4_6[m4_6['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_m3_7 = list(m4_6[m4_6['overdue_num'] == 3]['ACCOUNT_ID'])\n",
    "                list_all_c_7 = list(\n",
    "                    m4_6.loc[(m4_6['STATUS7'] == 'CLEAR') & (m4_6['REPAY_TIME7'] < '2019-7-11')]['ACCOUNT_ID']) + list(\n",
    "                    m7['ACCOUNT_ID'])\n",
    "\n",
    "                # 8月\n",
    "                # 取4-7月完成的数据\n",
    "                m4_7 = all[all['COMPLETE_TIME'].isin(list(range(4, 8)))].copy()\n",
    "                if m4_7.shape[0] > 0:\n",
    "                    # 判断逾期几期并记录到dataframe\n",
    "                    m4_7['overdue_num'] = m4_7.apply(lambda x: overdue_num(x=x, y=8), axis=1)\n",
    "                else:\n",
    "                    m4_7['overdue_num'] = 0\n",
    "                list_all_m1_8 = list(m4_7[m4_7['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_8 = list(m4_7[m4_7['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_m3_8 = list(m4_7[m4_7['overdue_num'] == 3]['ACCOUNT_ID'])\n",
    "                list_all_m4_8 = list(m4_7[m4_7['overdue_num'] == 4]['ACCOUNT_ID'])\n",
    "                list_all_c_8 = list(\n",
    "                    m4_7.loc[(m4_7['STATUS8'] == 'CLEAR') & (m4_7['REPAY_TIME8'] < '2019-8-11')]['ACCOUNT_ID']) + list(\n",
    "                    m8['ACCOUNT_ID'])\n",
    "\n",
    "                # 9月\n",
    "                # 取4-8月完成的数据\n",
    "                m4_8 = all[all['COMPLETE_TIME'].isin(list(range(4, 9)))].copy()\n",
    "                if m4_8.shape[0] > 0:\n",
    "                    # 判断逾期几期并记录到dataframe\n",
    "                    m4_8['overdue_num'] = m4_8.apply(lambda x: overdue_num(x=x, y=9), axis=1)\n",
    "                else:\n",
    "                    m4_8['overdue_num'] = 0\n",
    "                list_all_m1_9 = list(m4_8[m4_8['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_9 = list(m4_8[m4_8['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_m3_9 = list(m4_8[m4_8['overdue_num'] == 3]['ACCOUNT_ID'])\n",
    "                list_all_m4_9 = list(m4_8[m4_8['overdue_num'] == 4]['ACCOUNT_ID'])\n",
    "                list_all_m5_9 = list(m4_8[m4_8['overdue_num'] == 5]['ACCOUNT_ID'])\n",
    "                list_all_c_9 = list(\n",
    "                    m4_8.loc[(m4_8['STATUS9'] == 'CLEAR') & (m4_8['REPAY_TIME9'] < '2019-9-11')]['ACCOUNT_ID']) + list(\n",
    "                    m9['ACCOUNT_ID'])\n",
    "\n",
    "                # 10月\n",
    "                # 取4-9月完成的数据\n",
    "                m4_9 = all[all['COMPLETE_TIME'].isin(list(range(4, 10)))].copy()\n",
    "                if m4_9.shape[0] > 0:\n",
    "                     # 判断逾期几期并记录到dataframe\n",
    "                    m4_9['overdue_num'] = m4_9.apply(lambda x: overdue_num(x=x, y=10), axis=1)\n",
    "                else:\n",
    "                     m4_9['overdue_num'] = 0\n",
    "                list_all_m1_10 = list(m4_9[m4_9['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_10 = list(m4_9[m4_9['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_m3_10 = list(m4_9[m4_9['overdue_num'] == 3]['ACCOUNT_ID'])\n",
    "                list_all_m4_10 = list(m4_9[m4_9['overdue_num'] == 4]['ACCOUNT_ID'])\n",
    "                list_all_m5_10 = list(m4_9[m4_9['overdue_num'] == 5]['ACCOUNT_ID'])\n",
    "                list_all_m6_10 = list(m4_9[m4_9['overdue_num'] == 6]['ACCOUNT_ID'])\n",
    "                list_all_c_10 = list(\n",
    "                     m4_9.loc[(m4_9['STATUS10'] == 'CLEAR') & (m4_9['REPAY_TIME10'] < '2019-10-11')]['ACCOUNT_ID']) + list(\n",
    "                     m10['ACCOUNT_ID'])\n",
    "                \n",
    "                # 11月\n",
    "                # 取4-10月完成的数据\n",
    "                m4_10 = all[all['COMPLETE_TIME'].isin(list(range(4, 11)))].copy()\n",
    "                if m4_10.shape[0] > 0:\n",
    "                     # 判断逾期几期并记录到dataframe\n",
    "                    m4_10['overdue_num'] = m4_10.apply(lambda x: overdue_num(x=x, y=11), axis=1)\n",
    "                else:\n",
    "                     m4_10['overdue_num'] = 0\n",
    "                list_all_m1_11 = list(m4_10[m4_10['overdue_num'] == 1]['ACCOUNT_ID'])\n",
    "                list_all_m2_11 = list(m4_10[m4_10['overdue_num'] == 2]['ACCOUNT_ID'])\n",
    "                list_all_m3_11 = list(m4_10[m4_10['overdue_num'] == 3]['ACCOUNT_ID'])\n",
    "                list_all_m4_11 = list(m4_10[m4_10['overdue_num'] == 4]['ACCOUNT_ID'])\n",
    "                list_all_m5_11 = list(m4_10[m4_10['overdue_num'] == 5]['ACCOUNT_ID'])\n",
    "                list_all_m6_11 = list(m4_10[m4_10['overdue_num'] == 6]['ACCOUNT_ID'])\n",
    "                list_all_m7_11 = list(m4_10[m4_10['overdue_num'] == 7]['ACCOUNT_ID'])\n",
    "                list_all_c_11 = list(\n",
    "                     m4_10.loc[(m4_10['STATUS11'] == 'CLEAR') & (m4_10['REPAY_TIME11'] < '2019-11-11')]['ACCOUNT_ID']) + list(\n",
    "                     m11['ACCOUNT_ID'])\n",
    "\n",
    "\n",
    "                # 计算结果保存\n",
    "                with open('迁移率(10号)导出.txt', 'a+') as f:\n",
    "                    # C-M1\n",
    "                    for m in range(5, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_c_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_c_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},C-M1,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M1-M2\n",
    "                    for m in range(6, 12):\n",
    "                        fz = len(set(eval('list_all_m2_' + str(m))) & set(eval('list_all_m1_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m1_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M1-M2,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M2-M3\n",
    "                    for m in range(7, 12):\n",
    "                        fz = len(set(eval('list_all_m3_' + str(m))) & set(eval('list_all_m2_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m2_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M2-M3,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M3-M4\n",
    "                    for m in range(8, 12):\n",
    "                        fz = len(set(eval('list_all_m4_' + str(m))) & set(eval('list_all_m3_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m3_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M3-M4,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M4-M5\n",
    "                    for m in range(9, 12):\n",
    "                        fz = len(set(eval('list_all_m5_' + str(m))) & set(eval('list_all_m4_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m4_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M4-M5,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M5-M6\n",
    "                    for m in range(10, 12):\n",
    "                        fz = len(set(eval('list_all_m6_' + str(m))) & set(eval('list_all_m5_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m5_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M5-M6,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "                    \n",
    "                    # M6-M7\n",
    "                    for m in range(11, 12):\n",
    "                        fz = len(set(eval('list_all_m7_' + str(m))) & set(eval('list_all_m6_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m6_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M6-M7,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # C-M2\n",
    "                    #                     for m in range(6,10):\n",
    "                    #                         c_m1_z = len(set(eval('list_all_m1_'+str(m-1))) & set(eval('list_all_c_'+str(m-2))))\n",
    "                    #                         c_m1_m = len(eval('list_all_c_'+str(m-2)))\n",
    "                    #                         m1_m2_z = len(eval('list_all_m2_'+str(m)))\n",
    "                    #                         m1_m2_m = len(eval('list_all_m1_'+str(m-1)))\n",
    "                    #                         fz = c_m1_z * m1_m2_z\n",
    "                    #                         fm = c_m1_m * m1_m2_m\n",
    "                    #                         f.write(\"{},{},{},C-M2,20190{},{},{}\".format(i, j, k, m,fz, fm) + '\\n')\n",
    "\n",
    "                    # C-M3\n",
    "                    #                     for m in range(7,10):\n",
    "                    #                         c_m1_z = len(set(eval('list_all_m1_'+str(m-2))) & set(eval('list_all_c_'+str(m-3))))\n",
    "                    #                         c_m1_m = len(eval('list_all_c_'+str(m-3)))\n",
    "                    #                         m1_m2_m = len(eval('list_all_m1_'+str(m-2)))\n",
    "                    #                         m2_m3_z = len(eval('list_all_m3_'+str(m)))\n",
    "                    #                         fz = c_m1_z * m2_m3_z\n",
    "                    #                         fm = c_m1_m * m1_m2_m\n",
    "                    #                         f.write(\"{},{},{},C-M3,20190{},{},{}\".format(i, j, k, m,fz, fm) + '\\n')\n",
    "\n",
    "                    # C-M4\n",
    "                    #                     for m in range(8,10):\n",
    "                    #                         c_m1_z = len(set(eval('list_all_m1_'+str(m-3))) & set(eval('list_all_c_'+str(m-4))))\n",
    "                    #                         c_m1_m = len(eval('list_all_c_'+str(m-4)))\n",
    "                    #                         m1_m2_m = len(eval('list_all_m1_'+str(m-3)))\n",
    "                    #                         m3_m4_z = len(eval('list_all_m4_'+str(m)))\n",
    "                    #                         fz = c_m1_z * m3_m4_z\n",
    "                    #                         fm = c_m1_m * m1_m2_m\n",
    "                    #                         f.write(\"{},{},{},C-M4,20190{},{},{}\".format(i, j, k, m,fz, fm) + '\\n')\n",
    "\n",
    "                    # C-M5\n",
    "                    #                     for m in range(9,10):\n",
    "                    #                         c_m1_z = len(set(eval('list_all_m1_'+str(m-4))) & set(eval('list_all_c_'+str(m-5))))\n",
    "                    #                         c_m1_m = len(eval('list_all_c_'+str(m-5)))\n",
    "                    #                         m1_m2_m = len(eval('list_all_m1_'+str(m-4)))\n",
    "                    #                         m4_m5_z = len(eval('list_all_m5_'+str(m)))\n",
    "                    #                         fz = c_m1_z * m4_m5_z\n",
    "                    #                         fm = c_m1_m * m1_m2_m\n",
    "                    #                         f.write(\"{},{},{},C-M5,20190{},{},{}\".format(i, j, k, m,fz, fm) + '\\n')\n",
    "\n",
    "                    # C-C\n",
    "                    for m in range(5, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_c_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_c_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},C-C,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M1-C\n",
    "                    for m in range(6, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m1_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m1_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M1-C,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M2-C\n",
    "                    for m in range(7, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m2_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m2_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M2-C,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M3-C\n",
    "                    for m in range(8, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m3_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m3_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M3-C,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M4-C\n",
    "                    for m in range(9, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m4_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m4_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M4-C,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M5-C\n",
    "                    for m in range(10, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m5_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m5_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M5-C,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "                    \n",
    "                    # M6-C\n",
    "                    for m in range(11, 12):\n",
    "                        fz = len(set(eval('list_all_c_' + str(m))) & set(eval('list_all_m6_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m6_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M6-C,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "\n",
    "\n",
    "                    # M1-M1\n",
    "                    for m in range(6, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m1_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m1_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M1-M1,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M2-M1\n",
    "                    for m in range(7, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m2_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m2_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M2-M1,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M3-M1\n",
    "                    for m in range(8, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m3_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m3_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M3-M1,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "                    # M4-M1\n",
    "                    for m in range(9, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m4_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m4_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M4-M1,20190{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "                        \n",
    "                    # M5-M1\n",
    "                    for m in range(10, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m5_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m5_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M5-M1,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "                        \n",
    "                    # M6-M1\n",
    "                    for m in range(11, 12):\n",
    "                        fz = len(set(eval('list_all_m1_' + str(m))) & set(eval('list_all_m6_' + str(m - 1))))\n",
    "                        fm = len(eval('list_all_m6_' + str(m - 1)))\n",
    "                        f.write(\"{},{},{},M6-M1,2019{},{},{}\".format(i, j, k, m, fz, fm) + '\\n')\n",
    "\n",
    "print('迁移率数据写入完成！文件位置:{}'.format(os.getcwd()))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
